﻿package com.dLibs.utils
{
	import com.greensock.*;
	import com.greensock.easing.*;
	
	public class scaleObject
	{
		private var _image					:*;
		private var imageAspectRatio		:Number;
		private var stageAspectRatio		:Number;
		private var imageWidth				:Number;
		private var imageHeight				:Number;
		private var imageEase				:Boolean;		
		private var oldWidth				:Number;
		private var oldHeight				:Number;
		
		public function scaleObject(image:*,scaleData:Object):void
		{
			_image 				= image;			
			oldWidth 			= image.width;
			oldHeight 			= image.height;			
			imageWidth 			= scaleData.width;
			imageHeight 		= scaleData.height;	
			imageEase			= scaleData.ease;		
			imageAspectRatio 	= _image.width/_image.height;
			stageAspectRatio 	= imageWidth/imageHeight;
			
			if ( stageAspectRatio >= imageAspectRatio ) 
			{
				if ( imageEase ) 
				{ 
					TweenLite.to(_image, .5, { width : imageWidth, height : (imageWidth/imageAspectRatio), ease:Expo.easeInOut }); 
				}
				else 
				{ 
					_image.width = imageWidth;
					_image.height = (imageWidth/imageAspectRatio);
				}
			} 
			else
			{
				if ( imageEase ) 
				{
					TweenLite.to(_image, .5, { width : (imageHeight*imageAspectRatio), height : imageHeight, ease:Expo.easeInOut });
				}
				else
				{
					_image.width = (imageHeight*imageAspectRatio);
					_image.height = imageHeight;
				}
			}
		}
		
		public function resetSize():void
		{
			_image.width = oldWidth;
			_image.height = oldHeight;
		}

	}
}